<template>
	<view style="padding-top: 24rpx;">
		<view v-if="siteList.length>0">
			<view class="item" @click="getState(res)" v-for="(res, index) in siteList" :key="res.id">
				<view class="left_box">
					<image class="left_image" src="../static/address_tb3.png" v-if="res.tag"></image>
					<image class="left_image" src="../static/address_tb4.png" v-else></image>
				</view>
				<view class="con_box">
					<view class="top">
						<view class="name">{{ res.username }}</view>
						<view class="phone">{{ res.telphone }}</view>
					</view>
					<view class="bottom">
						{{res.region}} {{res.detail}}
						<!-- 	<u-icon name="edit-pen" :size="40" color="#999999"></u-icon> -->
					</view>
					<view class="tag">
						<text v-for="(item, index) in res.tag" :key="index"
							:class="{red:item.tagText=='默认'}">{{ item.tagText }}
						</text>
					</view>
				</view>
				<view class="right_box">
					<image class="right_image" src="../static/address_tb2.png"></image>
				</view>
			</view>
		</view>
		<view class="none" v-else>
			<view class="none-view">
				<image src="../../../static/image/none.png" class="none-image"></image>
				<view class="none-name">
					暂无相关数据~
				</view>
			</view>
		</view>
		<view class="addSite" @tap="toAddSite">
			<view class="add">
				<!-- 	<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>新建收货地址 -->
				添加地址
			</view>
		</view>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				siteList: [],
				state: 0,
				is_car: 0,
				arr: []
			};
		},
		onLoad(option) {
			than = this;
			if (option.state) {
				than.state = option.state
				than.is_car = parseInt(option.is_car)
				than.arr = JSON.parse(option.arr)
			}
		},
		onShow() {
			this.getData();
		},
		methods: {
			getData() {
				than.post("api/address/addressList", null, function(data) {
					than.siteList = [];
					if (!!data.default) {
						data.default.tag = [];
						data.default.tag.push({
							tagText: '默认'
						})
						than.siteList.push(data.default)
					}
					for (let i in data.other) {
						than.siteList.push(data.other[i])
					}
					//console.log(than.siteList)
				})
			},
			toAddSite() {
				uni.navigateTo({
					url: 'addSite'
				});
			},
			getState(data) {
				if (than.state == 0) {
					than.toPage('updateSite?aid=' + data.address_id)
				} else {
					uni.redirectTo({
						url: '/pages/htmlC/pay/index?data=' + JSON.stringify(data) + '&is_car=' + than.is_car +
							'&arr=' + JSON.stringify(
								than.arr)
					})
				}
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #FAFAFA;
	}

	.item {
		padding: 40rpx 20rpx;
		margin: 0 36rpx 24rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		display: flex;

		.con_box {
			flex: 1;
		}

		.left_box {
			margin-right: 20rpx;

			.left_image {
				width: 22rpx;
				height: 22rpx;
				margin-top: 15rpx;
			}
		}

		.right_box {
			display: flex;
			align-items: center;
			margin-left: 20rpx;

			.right_image {
				width: 40rpx;
				height: 39rpx;
			}
		}

		.top {
			display: flex;
			align-items: center;
			font-weight: bold;
			font-size: 34rpx;

			.phone {
				margin-left: 20rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
			}


		}

		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;

			text {
				display: block;
				width: 80rpx;
				height: 36rpx;
				line-height: 36rpx;
				color: #205FFA;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				//margin-left: 30rpx;
				margin-top: 20rpx;
				background-color: rgb(49, 145, 253);
			}

			.red {
				background: #F2F5FD;
			}
		}

		.bottom {
			display: flex;
			margin-top: 20rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #999999;
		}
	}

	.addSite {
		display: flex;
		justify-content: space-around;
		// width: 600rpx;
		// line-height: 100rpx;
		position: absolute;
		bottom: 30rpx;
		// left: 80rpx;
		left: 0;
		right: 0;
		margin: auto;
		// background-color: #FACA55;
		// border-radius: 60rpx;
		font-size: 30rpx;
		width: 245rpx;
		height: 74rpx;
		background: #FB683D;
		border-radius: 20rpx;

		.add {
			display: flex;
			align-items: center;
			color: #ffffff;

			.icon {
				margin-right: 10rpx;
			}
		}
	}
</style>
